
请百度搜索 "Ubuntu Server 随机启动"

打开 rc.local.service 文件，如下：
vi /lib/systemd/system/rc.local.service
( Ubuntu Server 22.04 中，其文件名是 rc-local.service )


将其中的 After=后面，换成 mysql.service 
After=mysql.service


确认在启动 HelpChat Server 之前，MySQL 数据库已经先启动好了！


然后
vi /etc/rc.local 

将 rc.local 的文件内容存进去

最后执行 
chmod 777 /etc/rc.local 

即可


Ubuntu Server 20.04 参见以下方式启用随机启动：
https://linuxmedium.com/how-to-enable-etc-rc-local-with-systemd-on-ubuntu-20-04/



Ubuntu Server 22.04 参见以下方式启用随机启动：
https://linuxmedium.com/how-to-enable-etc-rc-local-with-systemd-on-ubuntu-20-04/


Ubuntu Server 22.04 只需执行以下命令：
--------------------------------------------------------------------------------
sudo systemctl enable rc-local

然后
vi /etc/rc.local 

将 rc.local 的文件内容存进去

最后执行 
chmod 777 /etc/rc.local 

即可





对于 Ubuntu Server 22 中如果没有 /etc/rc.local 文件的，请按以下方式添加
------------------------------------------




sudo vi /etc/rc.local
------------------------------------------

#!/bin/bash
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

cd /www/bin_server/

./hclogin &
./hckernel &
./hcdata &
./hcadmin &
./hcaidrpr &

exit 0





------------------------------------------
sudo chmod +x /etc/rc.local

需要创建一个 systemd 服务单元文件来管理 rc.local 的启动。
sudo vi sudo nano /etc/systemd/system/rc-local.service


在文件中添加以下内容：
重点：确保是在 mysql.service 之后启动（以下已是正确配置）
------------------------------------------

[Unit]
Description=/etc/rc.local Compatibility
ConditionPathExists=/etc/rc.local
After=network.target mysql.service
Requires=mysql.service

[Service]
Type=forking
ExecStart=/etc/rc.local start
TimeoutSec=0
StandardOutput=tty
RemainAfterExit=yes
SysVStartPriority=99

[Install]
WantedBy=multi-user.target



查询 mysql.service 是否存在
------------------------------------------
systemctl status mysql.service



启用并启动 rc-local 服务
------------------------------------------
sudo systemctl daemon-reload
sudo systemctl enable rc-local
sudo systemctl start rc-local



检查 rc-local 服务状态
------------------------------------------
sudo systemctl status rc-local
